import request from '@/utils/request'
import form from '@/utils/form'
const api = 'UserReward/'
/**
 * 表彰管理
 *
 * @export
 * @param {*} { id, parentId, name, description, companyCode, color, startTime, endTime, period, isRemoved }
 * @return {*}
 */
export function RewardInfo({ id, parentId, name, description, companyCode, color, startTime, endTime, period, isRemoved }) {
  const appName = 'party-reward'
  return request.post(`${api}Info`, {
    data: {
      id, parentId, name, description, companyCode, color, appName, startTime, endTime, period, isRemoved
    },
    allowOverwrite: false
  })
}

//
/**
 * 表彰查询
 *
 * @export
 * @param {*} {
 *  page,
 *  filters,
 *  name,
 *  period,
 *  start Array[start,end],
 *  end Array[start,end],
 *  parent,
 *  appName,
 *  company
 *  }
 * @return {*}
 */
export function RewardList({ page, filters, name, period, start, end, parent, appName, company }) {
  parent = parent || null
  return request.post(`${api}List`,
    {
      page,
      name: form.toQueryValue(name),
      period: form.toQueryValue(period),
      appName: form.toQueryValue(appName),
      start: form.toQueryStartEndByArray(start),
      end: form.toQueryStartEndByArray(end),
      parent: form.toQueryValue(parent, true),
      company: form.toQueryValue(company)
    }
  )
}

/**
 * 表彰记录管理
 *
 * @export
 * @param {*} { isRemoved, id, rewardId, companyCode, round, createById, parent }
 * @return {*}
 */
export function RewardContentInfo({ isRemoved, id, rewardId, companyCode, round, createById, parent, targetUserId, targetCompanyCode }) {
  return request.post(`${api}RecordInfo`,
    {
      data: { isRemoved, id, rewardId, companyCode, round, createById, parent, targetUserId, targetCompanyCode },
      allowOverwrite: false
    }
  )
}

/**
 * 表彰记录查询
 *
 * @export
 * @param {*} {
 *  rewardId,
 *  page,
 *  orders,
 *  createBy,
 *  round,
 *  create,
 *  company
 *  }
 * @return {*}
 */
export function RewardRecordList({ rewardId, page, orders, createBy, round, create, company }) {
  return request.post(`${api}RecordList`, {
    rewardId,
    page,
    orders,
    createBy: form.toQueryValue(createBy),
    create: form.toQueryStartEndByArray([create, create]),
    round: form.toQueryStartEndByArray([round, round]),
    company: form.toQueryValue(company)
  })
}
